package com.vive.wicket;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.markup.html.include.Include;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.link.PopupSettings;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PopupLink extends WebPage {

    private static List SITES = new ArrayList();
    private static Map NAMES = new HashMap();

    static {
        SITES.add("http://aa.com");
        SITES.add("http://bb.com");
        SITES.add("http://cc.com");

        NAMES.put("http://aa.com", "aa");
        NAMES.put("http://bb.com", "bb");
        NAMES.put("http://cc.com", "cc");
    }
    public PopupLink(){


        super();



        BookmarkablePageLink pageLink = new BookmarkablePageLink("popupLink", PopupLink.class);

        PopupSettings popupSettings = new PopupSettings();
        popupSettings.setHeight(400);
        popupSettings.setWidth(400);
        pageLink.setPopupSettings(popupSettings);
        this.add(pageLink);

        add(new ExternalLink("externalLink", "https://www.baidu.com","百度"));

        Form form = new Form("formC");
        add(form);

        //单选
        form.add(new CheckBox("checkbox"));

        //多选
        IChoiceRenderer renderer = new ChoiceRenderer(){
            public Object getDisplayValue(Object object) {
                return NAMES.get(object);
            }
        };

        CheckBoxMultipleChoice siteChoice = new CheckBoxMultipleChoice<>("sites2", SITES, renderer);
        form.add(siteChoice);

        add(form);
        CheckGroup<Object> group = new CheckGroup<>("group", new ArrayList<>());
        form.add(group);
        group.add(new CheckGroupSelector("groupselector"));

        ListView listView = new ListView("sites3", SITES) {
            protected void populateItem(ListItem item) {
                Object object = item.getModelObject();
                item.add(new Check<>("check",new Model<>(Integer.toString(item.getIndex()))));
                item.add(new Label("name",new Model<>((Serializable) NAMES.get(object))));
            }
        };
        group.add(listView);
    }
}
